/* GUI CONVERTED from ecselprt.i (converter v1.76) Wed Apr  3 17:36:36 2002 */
/* ecselprt.i - INCLUDE FILE TO SELECT PRINTER FOR OUTPUT                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.2.1.9 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 1.0          LAST EDIT: 05/14/86          MODIFIED BY: EMB       */
/*           2.0                     11/15/86                       pml       */
/* REVISION: 4.0          LAST EDIT: 12/30/87       MODIFIED BY: WUG *A137*   */
/* REVISION: 4.0          LAST EDIT: 03/10/89       MODIFIED BY: WUG *A667*   */
/* REVISION: 5.0          LAST EDIT: 04/12/89       MODIFIED BY: WUG *B098*   */
/* REVISION: 5.0          LAST EDIT: 04/13/89       MODIFIED BY: WUG *B080*   */
/* REVISION: 5.0          LAST EDIT: 06/29/89       MODIFIED BY: emb *B164*   */
/* REVISION: 5.0          LAST EDIT: 06/29/89       MODIFIED BY: pml *B241*   */
/* REVISION: 5.0          LAST EDIT: 09/12/89       MODIFIED BY: tjt *B270*   */
/* REVISION: 5.0      LAST MODIFIED: 09/26/89   BY: MLB *B316*                */
/* REVISION: 5.0          LAST EDIT: 02/21/90       MODIFIED BY: MLB *B576**/
/* REVISION: 5.0          LAST EDIT: 05/23/90       MODIFIED BY: emb *B695**/
/* REVISION: 6.0          LAST EDIT: 05/30/90       MODIFIED BY: WUG *B%%%**/
/* REVISION: 7.0          LAST EDIT: 02/20/92       MODIFIED BY: WUG *F219**/
/* REVISION: 7.0          LAST EDIT: 05/21/92       MODIFIED BY: rwl *F556**/
/* Revision: 7.3          Last edit: 09/16/92       Modified by: jcd *G058**/
/* Revision: 7.3          Last edit: 11/25/92       Modified by: jcd *G361**/
/* Revision: 7.4          Last edit: 08/16/93       Modified by: QZL *H013**/
/* Revision: 7.4          Last edit: 12/15/95       Modified by: rwl *F0WR**/
/* Revision: 7.4          Last edit: 05/06/96       Modified by: rvw *H0KQ**/
/* Revision: 8.6          Last edit: 05/20/98    BY: *K1Q4* Alfred Tan        */
/* REVISION: 9.1          Last edit: 10/18/99    BY: *N03C* Kieran O Dea      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00    BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 09/05/00    BY: *N0RF* Mark Brown        */
/* REVISION: 9.1      LAST MODIFIED: 09/12/00    BY: *L12Y* Falguni Dalal     */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.2.1.9 $    BY: Jean Miller       DATE: 04/03/02  ECO: *P053*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* Parameters:                                                               */
/*    {1} Name of file to output to, e.g. "terminal", "printer"              */
/*    {2} Width of page, e.g. 80 or 132                                      */
/*    {3} (optional) "nopage" for programs printing checks or labels         */
/*    {4} (optional) stream name (must also include in mfrtrail.i)   *B164*  */
/*    {5} (optional) "append" (to append to disk files)              *B%%%*  */
/*****************************************************************************/
/* NOTE: CHANGES MADE TO THIS PROGRAM MAY NEED TO BE MADE TO mfselbpr.i      */
/*****************************************************************************/

/* To allow dev passed as variable and not displayed on screen */

define shared variable printdefault like prd_dev.
define shared variable printdefaultlevel as integer.

define variable chr_string as character format "X(64)".
define variable chr_position as integer.
define variable pagesize as integer.
define variable path like prd_path.
define variable spooler like prd_spooler.
define variable scrollonly like prd_scroll_only.
define variable l_destinationtype as integer no-undo.
define variable l_returnstatus as logical no-undo.
define variable l_textfile as character no-undo.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/  with frame a width 80 THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



printwidth = {2}.
printype = "{1}".

if dev = "" or dev = ? then do:

   if "{1}" = "terminal" then do:
      /* NEED A SPECIFICALLY DEFINED PRINTER DEFAULT FOR MOST INQUIRIES */
      if printdefault = "" or printdefaultlevel <> 1 then dev = "terminal".
      else dev = printdefault.
   end.

   else do:
      if printdefault <> "" then
         dev = printdefault.
      else do:
         if can-find(prd_det where prd_dev = "printer") then
            dev = "printer".
         else do:
            find last prd_det where prd_path <> "terminal"
                                and prd_dev <> "terminal"
            no-lock no-error.
            if available prd_det then
               dev = prd_dev.
            else
               dev = "printer".
         end.
      end.
   end.

end.

selprt:
do with frame a on error undo:
/*GUI*/ if global-beam-me-up then undo, leave.


   path = dev.
   scrollonly = no.

   find prd_det where prd_dev = dev no-lock no-error.

   if available prd_det then do:

      /*V8+*/

      if prd_scroll_only and "{3}" <> "" then do:
         /*Maximum Page Limit Printing not allowed with no-page option */
         {pxmsg.i &MSGNUM=89 &ERRORLEVEL=3}
         undo, retry.
      end.

      if prd_path <> "" then
         path = prd_path.

      scrollonly = prd_scroll_only.

   end.

   else do:
      {pxmsg.i &MSGNUM=34 &ERRORLEVEL=2}
      /* DEVICE ENTERED IS NOT A DEFINED PRINTER. */
      pause.
   end.

   if (path = "terminal" or path = "/dev/tty" or path = "tt:" or scrollonly)
      and "{4}" > ""
   then do:
      /* Terminal not allowed */
      {pxmsg.i &MSGNUM=35 &ERRORLEVEL=3}
      undo , retry.
   end.

end.
/*GUI*/ if global-beam-me-up then undo, leave.


status input.

assign
   maxpage = 0
   pagesize = 66
   spooler = no
   l_destinationtype = 0. /*SERVER PRINTER*/

if available prd_det then
   assign
      maxpage  = prd_max_page
      pagesize = prd_length
      spooler  = prd_spooler
      l_destinationtype = prd_dest_type.

if path = "printer" or opsys <> "unix" or scrollonly then
   spooler = no.

if scrollonly then do:
   path = mfguser + ".out".
   if search(path) <> ? then do:
      {gpfildel.i &filename=search(path)}
   end.
end.

else if not available prd_det and
   path <> "printer" and path <> "terminal"
then
   path = path + ".prn".

if available prd_det and prd_init_pro <> "" then do:
   if opsys = "unix" then
      unix silent value(prd_init_pro).
   else if opsys = "msdos" then
      dos silent value(prd_init_pro).
   else if opsys = "vms" then
      vms silent value(prd_init_pro).
end.

/*DETERMINE PRINT LENGTH*/
if "{3}" = "nopage" then
   /* OUTPUT WILL NOT BE PAGED */
   printlength = 0.
else
   /* PAGE SIZE OTHER THAN 0 MEANS THAT OUTPUT WILL BE PAGED */
   printlength = pagesize - 6.

/* THE VARIABLE printlength IS SET TO ZERO SO THAT WHEN */
/* LINES/PAGE SETTING IS SET TO ZERO REPORT OUTPUT WILL */
/* NOT HAVE PAGE BREAKS.                                */
if printlength < 0 then
   printlength = 0.

if path = "terminal" then do:

   if "{1}" = "printer" then
      /*THE EXISTENCE OF THE '_frozen' FIELD IN THE METASCHEMA WAS      */
      /*THE MECHANISM THAT WAS USED TO DETERMINE WHETHER THE VERSION OF */
      /* PROGRESS WAS VERSION 5.0 OR GREATER. IN TODAY'S RELEASES (9.*),*/
      /* THE CHECKING OF THE _frozen FLAG IS NO LONGER A RELEVANT       */
      /* EVENT AND ITS PRESENCE VIOLATES A STANDARD ON DIRECT QUERY     */
      /* OF THE METASCHEMA.                                             */
      {gprun.i ""gpseterm.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   if "{1}" = "printer" then
      output {4} to terminal paged.
   else
      release prd_det.

end.

/*SET OUTPUT DESTINATION FOR WINPRINT*/
     
else if l_destinationType = 2 then do: /*WINDOWS PRINTER*/
    {gprunp.i "gpwinprt" "p" "selectPrinter" "(output l_returnstatus)"}
    if l_returnstatus = true then do:
       l_textfile = "winprint" + mfguser + ".dat".
       output {4} to value(l_textfile) page-size value(printlength).
    end.
    else
       /*EXIT CURRENT .P PROGRAM */
       return.
end.
  

else do:

   /*SET OUTPUT DESTINATION FOR EMAIL*/
   if l_destinationType = 1 then do: /*EMAIL*/
      {gprunp.i "gpemail" "p" "getEmailDetails" "(output l_returnstatus)"}
      if l_returnstatus = true then do:
         l_textfile = "email" + mfguser + ".dat".
         output {4} to value(l_textfile) page-size value(printlength).
      end.
      else
         /*EXIT CURRENT .P PROGRAM */
         return.
   end.
   else if spooler then
      output {4} through value(path) page-size value(printlength).
   else
      output {4} to value(path) {5} page-size value(printlength).

end.

if available prd_det then do:
   if {2} = 132 then
      put {4} control prd_init + prd_st_132.
   else if {2} = 80 then
      put {4} control prd_init + prd_st_80.
   else
      put prd_init.
end.

hide frame selprt no-pause.

if "{1}" = "terminal" and path <> "terminal" then do:
   /* SET EXTERNAL LABELS */
   setFrameLabels(frame selprt:handle).
   display {4} dtitle skip(1) with no-box no-labels frame selprt page-top.
   view {4} frame a.
end.
